﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using UnityEngine;
using Framework;
using UnityEngine.UI;

namespace PokerGame
{
    public class InfoPanel : UIBase
    { 
        private Text txtName;
        private Text txtLv;
        private Text txtExp;
        private Text txtBean;
        private Slider sldExp;

        private void Awake()
        {
            Bind(UIEvent.REFRESH_INFO_PANEL);
            txtName = transform.Find("txtName").GetComponent<Text>();
            txtLv = transform.Find("txtLv").GetComponent<Text>();
            txtExp = transform.Find("txtExp").GetComponent<Text>();
            txtBean = transform.Find("txtBean").GetComponent<Text>();
            sldExp = transform.Find("sldExp").GetComponent<Slider>();
        }

        public override void Execute(int eventCode, object message)
        {
            switch (eventCode)
            {
                case UIEvent.REFRESH_INFO_PANEL:
                    //TODO: refreshview
                    break;
                default:
                    break;
            }
        }

        /// <summary>
        /// 更新用户名、等级、经验、豆子等
        /// </summary>
        private void RefreshView(string name, int lv, int exp, int bean)
        {
            txtName.text = name;
            txtLv.text = $"Lv.{lv}";
            //经验公式: maxExp = lv * 10    //自定义
            txtExp.text = $"{exp}/{lv * 100}";
            sldExp.value = (float)exp / lv * 100;
            txtBean.text = $"×{bean}";
        }
    }
}
